package org.sxm.cloud.framework.config;


import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CrossFilterConfigure {
	
		@Bean
		public FilterRegistrationBean<CorsFilter> corsFilter() {
			   UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
			   CorsConfiguration config = new CorsConfiguration();
			   config.setAllowCredentials(false);
			   config.addAllowedOrigin("*");
			   config.addAllowedHeader("*");
			   config.addAllowedMethod("*");
			   config.setMaxAge(5*60L);
			   source.registerCorsConfiguration("/**", config);
			   FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<CorsFilter>(new CorsFilter(source));
			   bean.setOrder(0);
			   return bean;
		}

}
